package com.ss.android.article.browser.view;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.GeolocationPermissions;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import com.ss.android.article.browser.FeedFragment;
import com.ss.android.article.browser.WebViewClientDelegate;
import com.ss.android.common.app.permission.PermissionsManager;

public final class BrowserWebChromeClient extends WebChromeClient {
    private static final String[] ACCESS_FINE_LOCATION_PERMISSION = new String[]{"android.permission.ACCESS_FINE_LOCATION"};
    @NonNull private final Activity mActivity;
    @NonNull private final Browser mBrowser;
    @NonNull private final WebViewClientDelegate d;
    private com.ss.android.article.browser.a.a e;

    BrowserWebChromeClient(@NonNull Activity activity, @NonNull FeedFragment feedFragment, @NonNull Browser browser) {
        this.mActivity = activity;
        this.d = feedFragment;
        this.mBrowser = browser;
        this.e = com.ss.android.article.browser.a.a.a();
    }

    static Activity getActivity(BrowserWebChromeClient arg1) {
        return arg1.mActivity;
    }

    @Nullable public final Bitmap getDefaultVideoPoster() {
        return BitmapFactory.decodeResource(this.mActivity.getResources(), 17301616);
    }

    public final View getVideoLoadingProgressView() {
        return LayoutInflater.from(this.mActivity).inflate(com.ss.android.article.browser.R.layout.jn, null);
    }

    public final void onCloseWindow(WebView arg1) {
    }

    public final boolean onCreateWindow(WebView arg2, boolean arg3, boolean arg4, Message arg5) {
        this.d.onCreateWindow(arg5);
        return true;
    }

    public final void onGeolocationPermissionsShowPrompt(@NonNull String arg5, @NonNull GeolocationPermissions.Callback arg6) {
        PermissionsManager.getInstance().requestPermission(this.mActivity, BrowserWebChromeClient.ACCESS_FINE_LOCATION_PERMISSION, new h(this, arg5, arg6));
    }

    public final void onHideCustomView() {
        this.d.onHideCustomView();
    }

    public final void onProgressChanged(WebView webView, int newProgress) {
        this.d.onProgressChanged(newProgress);
    }

    public final void onReceivedIcon(@NonNull WebView webView, Bitmap icon) {
        r.a(icon);
        String url = webView.getUrl();
        if(icon != null && url != null) {
            com.a.a.a v0_1 = this.e.a(icon, url);
            v0_1.b = android.support.design.a.c();
            v0_1.a();
        }
    }

    public final void onReceivedTitle(@Nullable WebView webView, @Nullable String title) {
        if(title == null || (title.isEmpty())) {
            this.mBrowser.a.setTitle(this.mActivity.getString(com.ss.android.article.browser.R.string.a1u));
        }
        else {
            this.mBrowser.a.setTitle(title);
        }

        if(webView != null && webView.getUrl() != null) {
            webView.getUrl();
        }
    }

    public final void onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback customViewCallback) {
        this.d.onShowCustomView(view, customViewCallback, requestedOrientation);
    }

    public final void onShowCustomView(View view, WebChromeClient.CustomViewCallback customViewCallback) {
        this.d.onShowCustomView(view, customViewCallback);
    }

    public final boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
        this.d.onShowFileChooser(filePathCallback);
        return true;
    }
}

